<tr>
    <td width="100%">
		<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
		  <tr>
		    <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
		    <td valign="middle" align="right">
	    		<?php echo xtc_draw_form('status', FILENAME_ORDERS, '', 'get'); ?>
	                <?php echo HEADING_TITLE_STATUS . ' ' . xtc_draw_pull_down_menu('status', array_merge(array(array('id' => '', 'text' => TEXT_ALL_ORDERS)),array(array('id' => '0', 'text' => TEXT_VALIDATING)), $orders_statuses), $_GET['status'], 'onChange="this.form.submit();"').xtc_draw_hidden_field(xtc_session_name(), xtc_session_id()); ?>
	          	</form>          
	           </td>
		  </tr>
		</table>
    </td>
  </tr>
  <tr>
    <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td valign="top">
        	<table width="100%" class="dataTable" cellspacing="0" cellpadding="0">
          <tr class="dataTableHeadingRow">
		  	<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CUSTOMERS; ?></td>
			<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CUSTOMERS_CID; ?></td>
            <td class="dataTableHeadingContent" align="right">Nr</td>
			<td class="dataTableHeadingContent" align="center">PDF</td>
			<td class="dataTableHeadingContent" align="center">R-Nr</td>
            <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ORDER_TOTAL; ?></td>
            <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_DATE_PURCHASED; ?></td>
            <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_STATUS; ?></td>
			<td class="dataTableHeadingContent" align="right">Land</td>
            <td class="dataTableHeadingContent last" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
          </tr>
<?php
require_once(DIR_FS_INC.'cseo_get_pdf_nr.inc.php');
require_once(DIR_FS_INC.'cseo_get_pdf.inc.php');
if ($_GET['cID']) {
	$cID = xtc_db_prepare_input($_GET['cID']);
	$orders_query_raw = "select o.orders_id, o.customers_country, o.afterbuy_success, o.afterbuy_id, o.customers_name, o.customers_id, o.customers_cid, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, o.orders_status, s.orders_status_name, ot.text as order_total from ".TABLE_ORDERS." o left join ".TABLE_ORDERS_TOTAL." ot on (o.orders_id = ot.orders_id), ".TABLE_ORDERS_STATUS." s where o.customers_id = '".xtc_db_input($cID)."' and (o.orders_status = s.orders_status_id and s.language_id = '".$_SESSION['languages_id']."' and ot.class = 'ot_total') or (o.orders_status = '0' and ot.class = 'ot_total' and  s.orders_status_id = '1' and s.language_id = '".$_SESSION['languages_id']."') order by orders_id DESC";
}
elseif ($_GET['status']=='0') {
		$orders_query_raw = "select o.orders_id, o.customers_country, o.afterbuy_success, o.afterbuy_id, o.customers_name, o.customers_cid, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, o.orders_status, ot.text as order_total from ".TABLE_ORDERS." o left join ".TABLE_ORDERS_TOTAL." ot on (o.orders_id = ot.orders_id) where o.orders_status = '0' and ot.class = 'ot_total' order by o.orders_id DESC";
}
elseif ($_GET['status']) {
		$status = xtc_db_prepare_input($_GET['status']);
		$orders_query_raw = "select o.orders_id, o.afterbuy_success, o.afterbuy_id, o.customers_name, o.customers_cid, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from ".TABLE_ORDERS." o left join ".TABLE_ORDERS_TOTAL." ot on (o.orders_id = ot.orders_id), ".TABLE_ORDERS_STATUS." s where o.orders_status = s.orders_status_id and s.language_id = '".$_SESSION['languages_id']."' and s.orders_status_id = '".xtc_db_input($status)."' and ot.class = 'ot_total' order by o.orders_id DESC";
} else {
	$orders_query_raw = "select o.orders_id, o.orders_status, o.customers_country, o.afterbuy_success, o.afterbuy_id, o.customers_name, o.customers_cid, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from ".TABLE_ORDERS." o left join ".TABLE_ORDERS_TOTAL." ot on (o.orders_id = ot.orders_id), ".TABLE_ORDERS_STATUS." s where (o.orders_status = s.orders_status_id and s.language_id = '".$_SESSION['languages_id']."' and ot.class = 'ot_total') or (o.orders_status = '0' and ot.class = 'ot_total' and  s.orders_status_id = '1' and s.language_id = '".$_SESSION['languages_id']."') order by o.orders_id DESC";
}
$orders_split = new splitPageResults($_GET['page'], ($_GET['anzahl']!='')?$_GET['anzahl']:'20', $orders_query_raw, $orders_query_numrows);
$orders_query = xtc_db_query($orders_query_raw);
$rows = 1;
while ($orders = xtc_db_fetch_array($orders_query)) {
	if (((!$_GET['oID']) || ($_GET['oID'] == $orders['orders_id'])) && (!$oInfo)) {
		$oInfo = new objectInfo($orders);
	}
	
	$rech_nr = '-';
	$pdf_ico = '-';
	$email = '';
	if(cseo_get_pdf_nr($orders['orders_id'], true) > '0') {
		$rech_nr = '<b>'.cseo_get_pdf_nr($orders['orders_id'], true).'</b>';
		$pdf_ico = xtc_image('images/icons/document-pdf-text.png', 'PDF');
		if(cseo_get_pdf_nr($orders['orders_id'], false, false, true) > 0)
			$email = xtc_image('images/icons/mail--arrow.png', 'Email');
	}
	
	if ((is_object($oInfo)) && ($orders['orders_id'] == $oInfo->orders_id)) {
		echo '<tr class="dataTableRowSelected"  onclick="document.location.href=\''.xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('oID')) . 'oID=' . $orders['orders_id']).'\'" onmouseover="this.style.cursor=\'pointer\'">' . "\n";
    } else {
    	if ($rows % 2 == 0)
    		$f = 'dataTableRow';
    	else
    		$f = '';
        echo '<tr class="'.$f.'" onclick="document.location.href=\''.xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('oID')) . 'oID=' . $orders['orders_id']).'\'" onmouseover="this.className=\'dataTableRowOver\';this.style.cursor=\'pointer\'" onmouseout="this.className=\''.$f.'\'">' . "\n";
    }
?>

			<td>
				<?php echo '<a href="' . xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('oID', 'action')) . 'oID=' . $orders['orders_id'] . '&action=edit') . '">
					' . $orders['customers_name'].'</a>'; ?>
			</td>
            <td align="right"><?php echo ($orders['customers_cid']!='')?$orders['customers_cid']:'-'; ?></td>
            <td align="right"><?php echo $orders['orders_id']; ?></td>
			<td align="center"><?php echo $pdf_ico.$email; ?></td>
			<td align="center"><?php echo $rech_nr; ?></td>
            <td align="right"><?php echo strip_tags($orders['order_total']); ?></td>
            <td align="center"><?php echo xtc_datetime_short($orders['date_purchased']); ?></td>
            <td align="right">
            	<?php if($orders['orders_status']!='0') { echo $orders['orders_status_name']; }else{ echo '<font color="#FF0000">'.TEXT_VALIDATING.'</font>';}?>
            </td>
            <td align="right"><?php echo $orders['customers_country']; ?></td>
            <?php if (AFTERBUY_ACTIVATED=='true') { ?>
            <td align="right"><?php

				if ($orders['afterbuy_success'] == 1) {
					echo $orders['afterbuy_id'];
				} else {
					echo 'TRANSMISSION_ERROR';
				}
			?></td>
            <?php } ?>
            <td align="right" class="last"><?php 
            	if ( (is_object($oInfo)) && ($orders['orders_id'] == $oInfo->orders_id) ) { 
            		echo xtc_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); 
            	} else { 
            		echo '<a href="' . xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('oID','dl','gp','ms')) . 'oID=' . $orders['orders_id']) . '">' . xtc_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; 
            		echo ' <a href="' . xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('oID','dl','gp','ms')) . 'oID=' . $orders['orders_id']) . '&action=edit">' . xtc_image(DIR_WS_IMAGES . 'icon_edit.gif', IMAGE_ICON_ORDER_EDIT) . '</a>';
            	}	?>
            </td>
		</tr>		
	<?php $rows++; } ?>
</table></td>
<?php

$heading = array ();
$contents = array ();
switch ($_GET['action']) {
	case 'delete' :
		$heading[] = array ('text' => '</form>');
		$heading[] = array ('text' => '<b>'.TEXT_INFO_HEADING_DELETE_ORDER.'</b>');
		$contents = array ('form' => xtc_draw_form('orders', FILENAME_ORDERS, xtc_get_all_get_params(array ('oID', 'action')).'oID='.$oInfo->orders_id.'&action=deleteconfirm'));
		$contents[] = array ('text' => '<br />'.xtc_draw_checkbox_field('restock').' '.TEXT_INFO_RESTOCK_PRODUCT_QUANTITY);

		if(defined('TABLE_PAYPAL')):
			$db_installed = false;
			$tables = mysql_list_tables(DB_DATABASE);
			while ($row = mysql_fetch_row($tables)) {
				if ($row[0] == TABLE_PAYPAL) $db_installed=true;
			}
			if ($db_installed==true):
				$query = "SELECT * FROM " . TABLE_PAYPAL . " WHERE xtc_order_id = '" . $oInfo->orders_id . "'";
				$query = xtc_db_query($query);
				if(xtc_db_num_rows($query)>0):
					$contents[] = array ('text' => '<br />'.xtc_draw_checkbox_field('paypaldelete').' '.TEXT_INFO_PAYPAL_DELETE);
				endif;
			endif;
		endif;
		$contents[] = array ('align' => 'center', 'text' => '<br /><input type="submit" class="button" value="'. BUTTON_DELETE .'"><a class="button" href="'.xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array ('oID', 'action')).'oID='.$oInfo->orders_id).'">' . BUTTON_CANCEL . '</a>');
		break;
		
	default :
		if (is_object($oInfo)) {
			$heading[] = array ('text' => '<b>['.$oInfo->orders_id.']&nbsp;&nbsp;'.xtc_datetime_short($oInfo->date_purchased).'</b>');

			$contents[] = array ('align' => 'center', 'text' => '<br /><a class="button" href="'.xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array ('oID', 'action', 'print_oID')).'oID='.$oInfo->orders_id.'&action=edit').'">'.BUTTON_EDIT.'</a> <a class="button" href="'.xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array ('oID', 'action', 'print_oID')).'oID='.$oInfo->orders_id.'&action=delete').'">'.BUTTON_DELETE.'</a><br /><br />');
			$contents[] = array ('align' => 'center', 'text' => '<a class="button" href="'.xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array ('oID', 'action')).'oID='.$oInfo->orders_id.'&action=send&sta=1&stc=0').'">'.'An Admin Erneut Versenden'.'</a><br /><br />');
			$contents[] = array ('align' => 'center', 'text' => '<a class="button" href="'.xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array ('oID', 'action')).'oID='.$oInfo->orders_id.'&action=send&sta=0&stc=1').'">'.'An Kunden Erneut Versenden'.'</a><br /><br />');

			if (AFTERBUY_ACTIVATED == 'true') {
				$contents[] = array ('align' => 'center','text' => '<a class="button" href="'.xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array ('oID', 'action')).'oID='.$oInfo->orders_id.'&action=afterbuy_send').'">'.BUTTON_AFTERBUY_SEND.'</a>');

			}
			$contents[] = array ('align' => 'center', 'text' => '<hr size="1" style="color:#ccc" />');
//PDF Rechnung
			if(isset($_SESSION['msg'])) {
				echo '<script type="text/javascript">
						jQuery(document).ready(function() {
							jQuery(".success_msg").fadeIn(function(){setTimeout(function(){jQuery(".success_msg").hide("slow");}, 5000);});
						});
					</script>';
				if(isset($_SESSION['msg']['dl'])) {
					$msg = $_SESSION['msg']['dl'];
				}
				if(isset($_SESSION['msg']['gp'])) {
					$msg .= $_SESSION['msg']['gp'];
				}
				if(isset($_SESSION['msg']['sm'])) {
					$msg .= $_SESSION['msg']['sm'];
				}
				unset($_SESSION['msg']);
				echo $msg;
			}
			$contents[] = array ('text' => '<u>PDF Rechnung</u>');
			echo xtc_draw_form('print', FILENAME_ORDERS, xtc_get_all_get_params(array('action','pdf','dl','gb')) . 'pdf=print_order&action=edit');
			
			if(cseo_get_pdf($_GET['oID'], false, true)) {
				$contents[] = array ('text' => xtc_image('images/icons/document-pdf-text.png', 'PDF', '', '', 'style="position:relative; top:3px"').' '.cseo_get_pdf($_GET['oID'], false, false, true));
				$contents[] = array ('text' => '<a class="button" href="'.xtc_href_link('create_pdf_download.php', 'oID='.$_GET['oID']).'">PDF Rechnung anzeigen</a>');
			} else {
				if(cseo_get_pdf_nr($_GET['oID'],true) > 0)
					$contents[] = array ('text' => ' - RechnungsNr: <input type="text" name="pdf_bill_nr" value="'.cseo_get_pdf_nr($_GET['oID'], false,true).'" size="10" />');
				else
					$contents[] = array ('text' => '- n&auml;chste RechNr: <input type="text" name="pdf_bill_nr" value="'.cseo_get_pdf_nr($_GET['oID'], false, true).'" size="10" />');
				
				$contents[] = array ('text' => '<input type="radio" class="toogle_choose" name="what_to_do" id="check_generate_rechnung" value="bill" checked="" />');
				$contents[] = array ('text' => '<nobr><label for="check_generate_rechnung">Die Rechnung noch einmal generieren?</label></nobr><br />');
				$contents[] = array ('text' => '<input type="radio" class="toogle_choose" name="what_to_do" id="check_lieferschein_generieren" value="delivery" />');
				$contents[] = array ('text' => '<nobr><label for="check_lieferschein_generieren">Lieferschein erstellen</label></nobr><br />');
				$contents[] = array ('text' => '<input type="radio" class="toogle_choose" name="what_to_do" id="check_rechnung_loeschen" value="pdf_rechnung_loeschen" />');		
				$contents[] = array ('text' => '<nobr><label for="check_rechnung_loeschen">Rechnung l&ouml;schen</label></nobr>');
				
				
				$contents[] = array ('text' => '<input type="submit" value="gew&auml;hlte Aktion durchf&uuml;hren" class="button" />');
				$contents[] = array ('text' => xtc_draw_hidden_field('oID', $_GET['oID']) . xtc_draw_hidden_field('page', $_GET['page']) . xtc_draw_hidden_field('type', 'rechnung'));

				
				
			}
//PDF Rechnung	
			
			$contents[] = array ('align' => 'center', 'text' => '<hr size="1" style="color:#ccc" />');

			$contents[] = array ('text' => '<br />'.TEXT_DATE_ORDER_CREATED.' '.xtc_date_short($oInfo->date_purchased));
			if (xtc_not_null($oInfo->last_modified))
				$contents[] = array ('text' => TEXT_DATE_ORDER_LAST_MODIFIED.' '.xtc_date_short($oInfo->last_modified));
				
			if ($oInfo->payment_method !='' && $oInfo->payment_method != 'no_payment') {	
				include(DIR_FS_CATALOG.'lang/'.$_SESSION['language'].'/modules/payment/'.$oInfo->payment_method.'.php');
		 		$payment_method = constant(strtoupper('MODULE_PAYMENT_'.$oInfo->payment_method.'_TEXT_TITLE'));
				$contents[] = array ('text' => '<br /><u>'.TEXT_INFO_PAYMENT_METHOD.'</u><br />&nbsp;'.$payment_method);
			}
			$order = new order($oInfo->orders_id);
			$contents[] = array ('text' => '<br /><br /><u>'.sizeof($order->products).' '.PRODUCTS.'</u>');
			for ($i = 0; $i < sizeof($order->products); $i ++) {
				$contents[] = array ('text' => $order->products[$i]['qty'].'x&nbsp;'.$order->products[$i]['name']);

				if (sizeof($order->products[$i]['attributes']) > 0) {
					for ($j = 0; $j < sizeof($order->products[$i]['attributes']); $j ++) {
						$contents[] = array ('text' => '<small>&nbsp;<i> - '.$order->products[$i]['attributes'][$j]['option'].': '.$order->products[$i]['attributes'][$j]['value'].'</i></small></nobr>');
					}
				}
			}
		}
		break;
}

if ((xtc_not_null($heading)) && (xtc_not_null($contents))) {
	echo '<td width="25%" valign="top">'."\n";
	$box = new box;
	echo $box->infoBox($heading, $contents);
	if (xtc_not_null($_GET['print_oID'])) {
		echo '<br><span class="button" onclick="';
		if ($_GET['print_invoice']=='on')
			echo 'window.invoice.close();';
		if ($_GET['print_packingslip']=='on')
			echo 'window.packingslip.close();';
		echo '">'.BUTTON_CLOSE_PRINT_PAGES.'</span>';
	}
	echo '</td>'."\n";
}
		$order_page_dropdown = '<form name="anzahl" action="'.$_SERVER['REQUEST_URI'].'" method="GET">'. "\n";
	
		if($_GET['oID'] != '')
			$order_page_dropdown .= xtc_draw_hidden_field('oID', $_GET['oID']);
		if($_GET['page'] != '')
			$order_page_dropdown .= xtc_draw_hidden_field('page', $_GET['page']) . "\n";
			
		$customers_options = array();
		
		$order_options[] = array('id' => '10', 'text' => '10'); 
		$order_options[] = array('id' => '20', 'text' => '20'); 
		$order_options[] = array('id' => '50', 'text' => '50'); 
		$order_options[] = array('id' => '100', 'text' => '100'); 
		
		$order_page_dropdown .= xtc_draw_pull_down_menu('anzahl', $order_options, ($_GET['anzahl'] != '' ? $_GET['anzahl'] : '20'), 'onchange="this.form.submit()"') . "\n";
		
		$order_page_dropdown .= '</form>' . "\n";
?>
      </tr>
	  <tr>
		<td colspan="5"><table border="0" cellspacing="0" cellpadding="10" width="100%">
		  <tr>
			<td class="smallText" valign="top" width="33.33%"><?php echo $orders_split->display_count($orders_query_numrows, ($_GET['anzahl']!='')?$_GET['anzahl']:'20', $_GET['page'], TEXT_DISPLAY_NUMBER_OF_ORDERS); ?></td>
			<td class="smallText" align="right" width="33.33%"><?php echo $orders_split->display_links($orders_query_numrows, ($_GET['anzahl']!='')?$_GET['anzahl']:'20', MAX_DISPLAY_PAGE_LINKS, $_GET['page'], xtc_get_all_get_params(array('page', 'oID', 'action'))); ?></td>
			<td align="right" width="33.33%">
				<?php echo 'Bestellungen pro Seite: '.$order_page_dropdown; ?>
			</td>
		  </tr>
		</table></td>
	  </tr>
    </table></td>
  </tr>